<template>
  <div class="article-page">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>面经后台</el-breadcrumb-item>
      <el-breadcrumb-item>面经管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="never" border="false">
      <template #header>
        <div class="header">
          <span>共 {{total}} 条记录</span>
          <el-button icon="el-icon-plus" size="small" type="primary" round>
            添加面经
          </el-button>
        </div>
      </template>
      <el-table :data="list" style="width: 100%">
        <el-table-column label="序号" type="index" width="50">
          <template slot-scope="{$index}">{{ pageSize*(current-1 )+$index+1}}</template>
        </el-table-column>
        <el-table-column prop="stem" label="标题" width="400">
        </el-table-column>
        <el-table-column prop="creator" label="作者"> </el-table-column>
        <el-table-column prop="likeCount" label="点赞"> </el-table-column>
        <el-table-column prop="views" label="浏览数"> </el-table-column>
        <el-table-column prop="createdAt" label="更新时间" width="200">
        </el-table-column>
        <el-table-column label="操作" width="120px">
    <template #default="{ row }">
      <div class="actions">
        <i
          class="el-icon-view"
          @click="drawerHandle('preview')"></i>
        <i
          class="el-icon-edit-outline"
          @click="drawerHandle('edit')"
        ></i>
        <i class="el-icon-delete" @click="del(row.id)"></i>
      </div>
    </template>
  </el-table-column>
      </el-table>
      
    </el-card>
    <!-- 分页 -->
    <el-pagination
  background
  @current-change="handleCurrentChange"
  :current-page="current"
  :page-size="pageSize"
  layout="prev, pager, next"
  :total="total"
>
</el-pagination>
<el-drawer :title="titleType" :visible.sync="drawer">
        <el-form label-width="80px">
          <el-form-item label="标题">
            <el-input placeholder="输入面经标题"></el-input>
          </el-form-item>
          <el-form-item label="内容">富文本编辑器</el-form-item>
          <el-form-item>
            <el-button type="primary">确认</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
      </el-drawer>
  </div>
</template>

<script>
import {getArticleList} from '@/api/article'
import { del } from 'vue'
export default {
  name: 'article-page',
  data() {
    return {
      current: 1,
      pageSize: 10,
      total: 0,
      list: [],
      drawer: false,
      title: ''
    }
  },
  created() {
    this.listData()
  },
  computed: {
    titleType () {
      if (this.title == 'add') {
        return '添加文章'
      } else if (this.title == 'edit') {
        return '编辑文章'
      } else {
        return '查看文章'
      }
    }
  },
  methods: {
    async listData () {
      const { data } = await getArticleList({
      current: this.current,
      pageSize: this.pageSize
    })
    this.list = data.rows
    this.total = data.total
  },
  handleCurrentChange(val){
    this.current = val
    this.listData()
  },
  del(id){
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.$message({
            message: '无删除权限，请联系管理员，别瞎几把乱操作',
          type: 'error'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      drawerHandle (type) {
      this.title = type
      this.drawer = true
    }
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 25px;

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
  }

  .actions {
    font-size: 18px;
    display: flex;
    justify-content: space-around;
    color: #666;

    >i:hover {
      color: rgba(114, 124, 245, 1);
      cursor: pointer;
    }
  }
}

.el-pagination {
  margin-top: 20px;
  text-align: center;
}

.el-breadcrumb {
  margin-top: 10px;
}

.el-form {
  padding-right: 40px;
}

.quill-editor {
  ::v-deep .ql-editor {
    height: 300px;
  }
}

.el-rate {
  padding: 10px 0;
}

.article-preview {
  padding: 0 40px 40px 40px;

  >h5 {
    font-size: 20px;
    color: #666;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 30px;
    margin: 0 0 20px 0;
  }
}</style>
